package com.ruoyi.web.controller.cms.nav;


import com.ruoyi.cms.navType.domain.CmsNavType;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cms.navItem.domain.CmsNavItem;
import com.ruoyi.cms.navItem.service.ICmsNavItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;

@RestController("AdminCmsNavItemController")
@RequestMapping("/admin/cms/nav/item")
public class CmsNavItemController extends BaseController {
    @Resource
    private ICmsNavItemService cmsNavItemService;

    /**
     * 查询菜单项目列表
     */
    //@PreAuthorize("@ss.hasPermi('cms:item:list')")
    @GetMapping("/list")
    public AjaxResult list(CmsNavItem cmsNavItem) {
        List<CmsNavItem> list = cmsNavItemService.selectCmsNavItemList(cmsNavItem);
        return success(list);
    }


    /**
     * 获取下拉列表
     *
     * @return
     */
    @GetMapping("/dropDownList")
    public AjaxResult dropDownList(CmsNavItem cmsNavItem) {
        List<CmsNavItem> list = cmsNavItemService.selectCmsNavItemList(cmsNavItem);
        return success(list);
    }

    /**
     * 导出菜单项目列表
     */
    //@PreAuthorize("@ss.hasPermi('cms:item:export')")
    @Log(title = "菜单项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsNavItem cmsNavItem) {
        List<CmsNavItem> list = cmsNavItemService.selectCmsNavItemList(cmsNavItem);
        ExcelUtil<CmsNavItem> util = new ExcelUtil<CmsNavItem>(CmsNavItem.class);
        util.exportExcel(response, list, "菜单项目数据");
    }

    /**
     * 获取菜单项目详细信息
     */
    //@PreAuthorize("@ss.hasPermi('cms:item:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(cmsNavItemService.selectCmsNavItemById(id));
    }

    /**
     * 新增菜单项目
     */
    //@PreAuthorize("@ss.hasPermi('cms:item:add')")
    @Log(title = "菜单项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsNavItem cmsNavItem) {
        cmsNavItem.setStatus("0");
        cmsNavItem.setCreateBy(getUsername());
        return toAjax(cmsNavItemService.insertCmsNavItem(cmsNavItem));
    }

    /**
     * 修改菜单项目
     */
    //@PreAuthorize("@ss.hasPermi('cms:item:edit')")
    @Log(title = "菜单项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsNavItem cmsNavItem) {
        return toAjax(cmsNavItemService.updateCmsNavItem(cmsNavItem));
    }

    /**
     * 删除菜单项目
     */
    //@PreAuthorize("@ss.hasPermi('cms:item:remove')")
    @Log(title = "菜单项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(cmsNavItemService.deleteCmsNavItemByIds(ids));
    }


    /**
     * 状态修改
     */
    //@PreAuthorize("@ss.hasPermi('system:role:edit')")
    @Log(title = "角色管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody CmsNavItem cmsNavItem) {
        cmsNavItem.setUpdateBy(getUsername());
        return toAjax(cmsNavItemService.updateCmsNavItemStatus(cmsNavItem));
    }
}
